package com.leet.code.simple_array;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/30 9:20
 */

public class SortArrayByParity {
    public int[] sortArrayByParity(int[] A) {
        int[] B = new int[A.length]; //结果数组
        int a = 0;   //偶数存放的位置下标索引
        int b = B.length - 1; //奇数存放的位置的下标索引
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 == 0) { //偶数被存进数组，偶数的下标索引加一
                B[a] = A[i];
                a++;
            } else { //奇数被存进数组，奇数的下标索引减一
                B[b] = A[i];
                b--;
            }
        }
        return B;
    }
}
